package demo;

import dao.ClassDao;
import dao.ScoreDao;
import dao.StudentDao;
import model.Classes;
import model.Score;

import java.text.MessageFormat;
import java.util.List;
import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-12-30 13:42
 */
public class exer8 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        while(true){
            System.out.println("请输入班级名称");
            String className;
            while (true) {
                className = scan.next();
                if (className == null || className.length() == 0) {
                    System.out.println("班级名称无效");
                } else {
                    break;
                }

            }
            ClassDao classDao = new ClassDao();
            Classes classIdByName = classDao.getClassIdByName(className);
            if(classIdByName==null){
                System.out.println("不存在该班级");

            }
            else {
                System.out.println("班级id为"+classIdByName.getId());
                break;
            }
        }
        ScoreDao scoreDao = new ScoreDao();
        System.out.println("请输入班级id");
        int class_id=scan.nextInt();
        List<Score> scores = scoreDao.deleteAll(class_id);
        if(scores==null||scores.isEmpty()){
            System.out.println("不存在该班级");
            return;
        }
        //输出班级
        for (Score score:scores) {
            String format = MessageFormat.format("学生：{0}\t|学科：{1}\t|分数：{2}\t", score.getStudent().getName(), score.getCourse().getName(), score.getScore());
            System.out.println(format);
        }
    }
}
